@extends('layouts.app')
@section('content')
    <h1 class="mb-3 font-normal">{{$repository->title}}</h1>

    @foreach($grouped_chapters as $key=>$chapters)

        @switch($key)
            @case(\App\Models\ChapterRepository::STATUS_UNUSED)
            <h2 class="my-4">历史版本</h2>
            @break
            @case(\App\Models\ChapterRepository::STATUS_USING)
            <h2 class="my-4 text-primary">当前版本</h2>
            @break
            {{--@case(\App\Models\ChapterRepository::STATUS_PULL_REQUEST)--}}
            {{--<h2 class="my-4">请求合并</h2>--}}
            {{--@break--}}
            {{--@case(\App\Models\ChapterRepository::STATUS_PULL_REQUEST_REJECTED)--}}
            {{--<h2 class="my-4">拒绝合并</h2>--}}
            {{--@break--}}
        @endswitch
        @foreach($chapters as $chapter)
            <tig-chapter-item :chapter="{{json_encode($chapter)}}" :repository_id="{{$repository->id}}">
                @if($key==\App\Models\ChapterRepository::STATUS_USING)
                    @can('repositories.create-chapter',$repository)
                        <a class="btn btn-white p-2 block"
                           href="{{route('repositories.chapters.edit',['repository'=>$repository,'chapter'=>$chapter])}}">更新本章节</a>
                    @endcan
                @endif
                @can('repositories.push',$repository)
                    <tig-form
                            action="{{route('repositories.chapters.push',['repository'=>$repository,'chapter'=>$chapter])}}">
                        <input type="hidden" name="sequence" value="{{$chapter->pivot->sequence}}">
                        <button class="btn btn-white p-2 block"
                                type="submit">推送此版本
                        </button>
                    </tig-form>
                @endcan
                {{--@can('repositories.create-chapter',$repository)--}}
                {{--<a class="btn btn-white p-2 block"--}}
                {{--href="{{url('/repositories/'.$repository->id.'/chapters/'.$chapter->id.'/edit')}}">以此版本内容更新章节</a>--}}
                {{--@endcan--}}
                @if($key!=\App\Models\ChapterRepository::STATUS_USING)
                    @can('repositories.switch-chapter',$repository)
                        <tig-form
                                action="{{route('repositories.sequences.switch-chapter',['repository'=>$repository,'sequence'=>$chapter->pivot->sequence])}}"
                                :is-update="true">
                            <input type="hidden" name="id" value="{{$chapter->id}}">
                            <button class="btn btn-white p-2 block"
                                    type="submit">使用此版本
                            </button>
                        </tig-form>
                    @endcan
                @endif
                @can('chapters.delete',$chapter)
                    <tig-form action="{{route('chapters.destroy',['chapter'=>$chapter])}}" :is-delete="true">
                        <button type="submit" class="btn btn-white hover:text-danger p-2 block">删除</button>
                    </tig-form>
                @endcan
            </tig-chapter-item>
        @endforeach
    @endforeach

@endsection